﻿/*
* BDCjsjFunc.cs
*
* 功 能： 采集数据通用类
* 类 名： BDCjsjFunc
*
* Ver    变更日期  20131203   负责人  黄永生  变更内容
* ───────────────────────────────────

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DQYT.HTDZ.Common;
using DQYT.HTDZ.Model;
using DQYT.HTDZ.BLL;
using System.Data;
using DQYT.HTDZ.BusinessService;

namespace DQYT.HTDZ.BusinessService
{
   public  class BDCjsjFunc
    {

        /// <summary>
        /// 获得示功图的驴头位移和悬点载荷数据
        /// </summary>
        /// <param name="listModel"></param>
        /// <returns></returns>
        public DataTable getSGT(List<CJSJModel> listModel)
        {
            DataTable dt = new DataTable();
            //添加列名
            dt.Columns.Add("LTWY", typeof(System.Double));// 驴头位移
            dt.Columns.Add("XDZH", typeof(System.Double));// 悬点载荷
            for (int i = 0; i < listModel.Count; i++)
            {
                CJSJModel model = listModel[i];
                DataRow row = dt.NewRow();
                row["LTWY"] =Math.Round(((double)model.LTWY+0.001), 2);
                row["XDZH"] =Math.Round(((double)model.XDZH+0.001), 2);
                dt.Rows.Add(row);
            }
            return dt;
        }
        /// <summary>
        /// 获得采集基础数据model
        /// </summary>
        /// <param name="wellid"></param>
        /// <param name="jcrq"></param>
        /// <returns></returns>
        public BDDATESOURCEModel getdatesousemodel(string wellid, string jcrq)
        {
            DataSet ds = new DataSet();
            string sqlstr = "select ID from BDDATESOURSE where JCRQ=to_date( '" + jcrq + "','yyyy-MM-dd HH24:mi:ss') and trim(WELLID)='" + wellid + "'";
            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            ds = bll.GetList_SQL(sqlstr);
            decimal id = (decimal)ds.Tables[0].Rows[0][0];
            BDDATESOURCEModel model = new BDDATESOURCEModel();
            model = bll.GetModel(id);
            return model;


        }
       /// <summary>
       /// 获得某个参数的一列数据
       /// </summary>
       /// <param name="wellid"></param>
       /// <param name="jcrq"></param>
       /// <param name="paramete"></param>
       /// <returns></returns>
        public DataTable getSingleParaData(string wellid, string jcrq, string paramete)
        {
            string strSql = "select CJSJ FROM BDDATESOURSE  where trim(WELLID)='" + wellid + "' and JCRQ=to_date( '" + jcrq + "','yyyy-MM-dd HH24:mi:ss')";
            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            DataTable Tb = bll.GetList_SQL(strSql).Tables[0];//获得一条记录
            byte[] btCjsj = (byte[])Tb.Rows[0]["CJSJ"];
            List<CJSJModel> cjsjModels = BinarySerializer.DeserializeObject<List<CJSJModel>>(btCjsj);
            if (paramete == "SGT")
            {
                Tb = getSGT(cjsjModels);
            }
            else
            {
                Tb = listCJSJModelToDataTable(cjsjModels, paramete);//提取欲描图参数
            }
            return Tb;
        }
        /// <summary>
        /// 将List<CJSJModel>的值提取出来放在DataTable中
        /// </summary>
        /// <param name="listModel"></param>
        /// <returns>DataTable</returns>
        public DataTable listCJSJModelToDataTable(List<CJSJModel> listModel, string drawValue)
        {
            DataTable dt = new DataTable();
            dt = setTableColumnsName(dt, drawValue);
            for (int i = 0; i < listModel.Count; i++)
            {
                CJSJModel model = listModel[i];
                dt = ModelToDataRow(model, dt, listModel.Count, drawValue);
            }
            return dt;
        }
        /// <summary>
        /// 将List<CJSJModel>的值提取出来放在DataTable中
        /// </summary>
        /// <param name="listModel"></param>
        /// <returns>DataTable</returns>
        public DataTable listCJSJModelToDataTable(List<CJSJModel> listModel)
        {
            DataTable dt = new DataTable();
            dt = setTableColumnsName(dt);
            for (int i = 0; i < listModel.Count; i++)
            {
                CJSJModel model = listModel[i];
                dt = ModelToDataRow(model, dt, listModel.Count);
            }
            return dt;
        }
        /// <summary>
        /// 添加table的列名
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public DataTable setTableColumnsName(DataTable dt, string drawValue)
        {
            dt.Columns.Add(drawValue, typeof(System.Double));// 描图参数
            return dt;
        }
        /// <summary>
        /// 添加table的列名
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public DataTable setTableColumnsName(DataTable dt)
        {
            dt.Columns.Add("AYGGL", typeof(System.Double));
            dt.Columns.Add("BYGGL", typeof(System.Double));
            dt.Columns.Add("CYGGL", typeof(System.Double));
            dt.Columns.Add("HYGGL", typeof(System.Double));
            dt.Columns.Add("AWGGL", typeof(System.Double));
            dt.Columns.Add("BWGGL", typeof(System.Double));
            dt.Columns.Add("CWGGL", typeof(System.Double));
            dt.Columns.Add("HWGGL", typeof(System.Double));
            dt.Columns.Add("ADY", typeof(System.Double));
            dt.Columns.Add("BDY", typeof(System.Double));
            dt.Columns.Add("CDY", typeof(System.Double));
            dt.Columns.Add("HDY", typeof(System.Double));
            dt.Columns.Add("ADL", typeof(System.Double));
            dt.Columns.Add("BDL", typeof(System.Double));
            dt.Columns.Add("CDL", typeof(System.Double));
            dt.Columns.Add("HDL", typeof(System.Double));
            dt.Columns.Add("AGLYS", typeof(System.Double));
            dt.Columns.Add("BGLYS", typeof(System.Double));
            dt.Columns.Add("CGLYS", typeof(System.Double));
            dt.Columns.Add("HGLYS", typeof(System.Double));
            dt.Columns.Add("ASZGL", typeof(System.Double));
            dt.Columns.Add("BSZGL", typeof(System.Double));
            dt.Columns.Add("CSZGL", typeof(System.Double));
            dt.Columns.Add("HSZGL", typeof(System.Double));
            dt.Columns.Add("DJSCNJ", typeof(System.Double));
            dt.Columns.Add("DJSCZS", typeof(System.Double));
            dt.Columns.Add("DJXL", typeof(System.Double));
            dt.Columns.Add("JSJSCNJ", typeof(System.Double));
            dt.Columns.Add("QBZJ", typeof(System.Double));
            dt.Columns.Add("LTWY", typeof(System.Double));
            dt.Columns.Add("XDZH", typeof(System.Double));
            dt.Columns.Add("YY", typeof(System.Double));
            dt.Columns.Add("TY", typeof(System.Double));
            dt.Columns.Add("WD", typeof(System.Double));
            dt.Columns.Add("YMGD", typeof(System.Double));
            dt.Columns.Add("YGNH", typeof(System.Double));
            dt.Columns.Add("WGNH", typeof(System.Double));
            dt.Columns.Add("PL", typeof(System.Double));

            return dt;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <param name="dt"></param>
        /// <param name="listNum"></param>
        /// <param name="drawValue"></param>
        /// <returns></returns>
        public DataTable ModelToDataRow(CJSJModel model, DataTable dt, int listNum, string drawValue)
        {
            DataRow row = dt.NewRow();
            int n = dt.Rows.Count + 1;
            switch (drawValue)
            {
                case "AYGGL": row["AYGGL"] =Math.Round(((double)model.AYGGL+0.00001), 4); break;
                case "BYGGL": row["BYGGL"] =Math.Round(((double)model.BYGGL+0.00001), 4); break;
                case "CYGGL": row["CYGGL"] =Math.Round(((double)model.CYGGL+0.00001), 4); break;
                case "HYGGL": row["HYGGL"] =Math.Round(((double)model.HYGGL+0.00001), 4); break;
                case "AWGGL": row["AWGGL"] =Math.Round(((double)model.AWGGL+0.00001), 4); break;
                case "BWGGL": row["BWGGL"] =Math.Round(((double)model.BWGGL+0.00001), 4); break;
                case "CWGGL": row["CWGGL"] =Math.Round(((double)model.CWGGL+0.00001), 4); break;
                case "HWGGL": row["HWGGL"] =Math.Round(((double)model.HWGGL+0.00001), 4); break;
                case "ADY": row["ADY"] =Math.Round(((double)model.ADY+0.00001), 4); break;
                case "BDY": row["BDY"] =Math.Round(((double)model.BDY+0.00001), 4); break;
                case "CDY": row["CDY"] =Math.Round(((double)model.CDY+0.00001), 4); break;
                case "HDY": row["HDY"] =Math.Round(((double)model.HDY+0.00001), 4); break;
                case "ADL": row["ADL"] =Math.Round(((double)model.ADL+0.00001), 4); break;
                case "BDL": row["BDL"] =Math.Round(((double)model.BDL+0.00001), 4); break;
                case "CDL": row["CDL"] =Math.Round(((double)model.CDL+0.00001), 4); break;
                case "HDL": row["HDL"] =Math.Round(((double)model.HDL+0.00001), 4); break;
                case "AGLYS": row["AGLYS"] =Math.Round(((double)model.AGLYS+0.00001), 4); break;
                case "BGLYS": row["BGLYS"] =Math.Round(((double)model.BGLYS+0.00001), 4); break;
                case "CGLYS": row["CGLYS"] =Math.Round(((double)model.CGLYS+0.00001), 4); break;
                case "HGLYS": row["HGLYS"] =Math.Round(((double)model.HGLYS+0.00001), 4); break;
                case "ASZGL": row["ASZGL"] =Math.Round(((double)model.ASZGL+0.00001), 4); break;
                case "BSZGL": row["BSZGL"] =Math.Round(((double)model.BSZGL+0.00001), 4); break;
                case "CSZGL": row["CSZGL"] =Math.Round(((double)model.CSZGL+0.00001), 4); break;
                case "HSZGL": row["HSZGL"] =Math.Round(((double)model.HSZGL+0.00001), 4); break;
                case "DJSCNJ": row["DJSCNJ"] =Math.Round(((double)model.DJSCNJ+0.00001), 4); break;
                case "DJSCZS": row["DJSCZS"] =Math.Round(((double)model.DJSCZS+0.00001), 4); break;
                case "DJXL": row["DJXL"] =Math.Round(((double)model.DJXL+0.00001), 4); break;
                case "JSJSCNJ": row["JSJSCNJ"] =Math.Round(((double)model.JSJSCNJ+0.001), 2); break;
                case "QBZJ": row["QBZJ"] =Math.Round(((double)model.QBZJ+0.00001), 4); break;
                case "LTWY": row["LTWY"] =Math.Round(((double)model.LTWY+0.00001), 4); break;
                case "XDZH": row["XDZH"] =Math.Round(((double)model.XDZH+0.00001), 4); break;
                case "YY": row["YY"] =Math.Round(((double)model.YY+0.00001), 4); break;
                case "TY": row["TY"] =Math.Round(((double)model.TY+0.00001), 4); break;
                case "WD": row["WD"] =Math.Round(((double)model.WD+0.00001), 4); break;
                case "YMGD": row["YMGD"] =Math.Round(((double)model.YMGD+0.00001), 4); break;
                case "YGNH": row["YGNH"] =Math.Round(((double)model.YGNH+0.00001), 4); break;
                case "WGNH": row["WGNH"] =Math.Round(((double)model.WGNH+0.00001), 4); break;
                case "PL": row["PL"] =Math.Round(((double)model.PL+0.00001), 4); break;

            }

            dt.Rows.Add(row);
            return dt;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <param name="dt"></param>
        /// <param name="listNum"></param>
        /// <param name="drawValue"></param>
        /// <returns></returns>
        public DataTable ModelToDataRow(CJSJModel model, DataTable dt, int listNum)
        {
            DataRow row = dt.NewRow();
            int n = dt.Rows.Count + 1;
            row["AYGGL"] =Math.Round(((double)model.AYGGL+0.00001), 4);
            row["BYGGL"] =Math.Round(((double)model.BYGGL+0.00001),4);
            row["CYGGL"] =Math.Round(((double)model.CYGGL+0.00001), 4);
            row["HYGGL"] =Math.Round(((double)model.HYGGL+0.00001), 4);
            row["AWGGL"] =Math.Round(((double)model.AWGGL+0.00001), 4);
            row["BWGGL"] =Math.Round(((double)model.BWGGL+0.00001), 4);
            row["CWGGL"] =Math.Round(((double)model.CWGGL+0.00001), 4);
            row["HWGGL"] =Math.Round(((double)model.HWGGL+0.00001), 4);
            row["ADY"] =Math.Round(((double)model.ADY+0.00001), 4);
            row["BDY"] =Math.Round(((double)model.BDY+0.00001), 4);
            row["CDY"] =Math.Round(((double)model.CDY+0.00001), 4);
            row["HDY"] =Math.Round(((double)model.HDY+0.00001), 4);
            row["ADL"] =Math.Round(((double)model.ADL+0.00001), 4);
            row["BDL"] =Math.Round(((double)model.BDL+0.00001), 4);
            row["CDL"] =Math.Round(((double)model.CDL+0.00001), 4);
            row["HDL"] =Math.Round(((double)model.HDL+0.00001), 4);
            row["AGLYS"] =Math.Round(((double)model.AGLYS+0.00001),4);
            row["BGLYS"] =Math.Round(((double)model.BGLYS+0.00001), 4);
            row["CGLYS"] =Math.Round(((double)model.CGLYS+0.00001), 4);
            row["HGLYS"] =Math.Round(((double)model.HGLYS+0.00001), 4);
            row["ASZGL"] =Math.Round(((double)model.ASZGL+0.00001), 4);
            row["BSZGL"] =Math.Round(((double)model.BSZGL+0.00001), 4);
            row["CSZGL"] =Math.Round(((double)model.CSZGL+0.00001), 4);
            row["HSZGL"] =Math.Round(((double)model.HSZGL+0.00001), 4);
            row["DJSCNJ"] =Math.Round(((double)model.DJSCNJ+0.00001), 4);
            row["DJSCZS"] =Math.Round(((double)model.DJSCZS+0.00001), 4);
            row["DJXL"] =Math.Round(((double)model.DJXL+0.00001), 4);
            row["JSJSCNJ"] =Math.Round(((double)model.JSJSCNJ+0.00001), 4);
            row["QBZJ"] =Math.Round(((double)model.QBZJ+0.00001), 4);
            row["LTWY"] =Math.Round(((double)model.LTWY+0.00001), 4);
            row["XDZH"] =Math.Round(((double)model.XDZH+0.00001), 4);
            row["YY"] =Math.Round(((double)model.YY+0.00001), 4);
            row["TY"] =Math.Round(((double)model.TY+0.00001), 4);
            row["WD"] =Math.Round(((double)model.WD+0.00001), 4);
            row["YMGD"] =Math.Round(((double)model.YMGD+0.00001), 4);
            row["YGNH"] =Math.Round(((double)model.YGNH+0.00001), 4);
            row["WGNH"] =Math.Round(((double)model.WGNH+0.00001), 4);
            row["PL"] =Math.Round(((double)model.PL+0.00001), 4);

            dt.Rows.Add(row);
            return dt;
        }
    }
      

}
